﻿#region Librerias
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
#endregion

/// <summary>
/// Class News, define las noticias para el apartado tipo blog
/// </summary>

#region Class

public class clsProyect : DAC
{
    #region Variables

    private int idProyect, idCategory;
    private String sTitle, sDescription, sUrlImage, sWebSiteAddress;
    private const String tabla = "dbo.tblProyect";

    #endregion

    #region Builder

    /// <summary>
    /// Constructor
    /// </summary>
    public clsProyect() { }

    #endregion

    #region Methods

    #region Consultations

    public DataSet SeeAllTheRecords()
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idProyect) As NUMBER, ";
        query += tabla + ".idProyect As ID, " + tabla + ".idCategory As CATEGORY, ";
        query += tabla + ".sTitle As TITLE, " + tabla + ".sDescription As DESCRIPTION, ";
        query += tabla + ".sUrlImage As URLIMAGE, " + tabla + ".sWebSiteAddress As WEBSITEADDRESS ";
        query += "FROM " + tabla;
        return this.ExecuteQuery(query);
    }

    public DataSet SeeAllTheRecords(int startRecord, int maxRecord, String text)
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idProyect) As NUMBER, ";
        query += tabla + ".idProyect As ID, " + tabla + ".idCategory As CATEGORY, ";
        query += tabla + ".sTitle As TITLE, " + tabla + ".sDescription As DESCRIPTION, ";
        query += tabla + ".sUrlImage As URLIMAGE, " + tabla + ".sWebSiteAddress As WEBSITEADDRESS ";
        query += "FROM " + tabla;
        if (!text.Equals(""))
        {
            query += " WHERE " + tabla + ".sTitle LIKE '%" + text + "%' ";
            query += "OR " + tabla + ".sDescription LIKE '%" + text + "%'";
        }
        if (startRecord == 0 && maxRecord == 0)
        {
            return this.ExecuteQuery(query);
        }
        else
        {
            return this.ExecuteQuery(query, startRecord, maxRecord);
        }
    }

    public DataSet ConsultID(String id)
    {
        String query = "SELECT ";
        query += tabla + ".idProyect As ID, " + tabla + ".idCategory As CATEGORY, ";
        query += tabla + ".sTitle As TITLE, " + tabla + ".sDescription As DESCRIPTION, ";
        query += tabla + ".sUrlImage As URLIMAGE, " + tabla + ".sWebSiteAddress As WEBSITEADDRESS ";
        query += "FROM " + tabla;
        query += " WHERE " + tabla + ".idProyect =" + id;
        return this.ExecuteQuery(query);
    }

    public DataSet ConsultCategoryID(String id)
    {
        String query = "SELECT ";
        query += tabla + ".idProyect As ID, " + tabla + ".idCategory As CATEGORY, ";
        query += tabla + ".sTitle As TITLE, " + tabla + ".sDescription As DESCRIPTION, ";
        query += tabla + ".sUrlImage As URLIMAGE, " + tabla + ".sWebSiteAddress As WEBSITEADDRESS ";
        query += "FROM " + tabla;
        query += " WHERE " + tabla + ".idCategory =" + id;
        return this.ExecuteQuery(query);
    }

    #endregion

    public int Insert()
    {
        String query = "INSERT INTO " + tabla;
        query += "(idCategory, sTitle, sDescription, sUrlImage, sWebSiteAddress) ";
        query += "VALUES ('{0}','{1}','{2}','{3}','{4}')";

        String sql = String.Format(query, this.IdCategory, this.STitle, this.SDescription, this.SUrlImage,this.SWebSiteAddress);
        return this.ExecuteDML(sql, "no");
    }

    public int Update()
    {
        String query = "UPDATE " + tabla + " SET ";
        query += tabla + ".idCategory=" + this.IdCategory + ", " + tabla + ".sTitle='" + this.STitle + "', ";
        query += tabla + ".sDescription='" + this.SDescription + "', " + tabla + ".sUrlImage='" + this.SUrlImage + "', ";
        query += tabla + ".sWebSiteAddress='" + this.SWebSiteAddress + "' ";
        query += "WHERE ";
        query += tabla + ".idProyect=" + this.ID;
        return this.ExecuteDML(query, "no");
    }

    public int Delete()
    {
        String query = "DELETE FROM " + tabla + " WHERE " + tabla + ".idProyect={0}";
        String sql = String.Format(query, this.ID);
        return this.ExecuteDML(sql, "no");
    }

    #endregion

    #region Setters and Getters


    public int IdCategory
    {
        get { return idCategory; }
        set { idCategory = value; }
    }

    public int ID
    {
        get { return idProyect; }
        set { idProyect = value; }
    }

    public String SWebSiteAddress
    {
        get { return sWebSiteAddress; }
        set { sWebSiteAddress = value; }
    }

    public String SUrlImage
    {
        get { return sUrlImage; }
        set { sUrlImage = value; }
    }

    public String SDescription
    {
        get { return sDescription; }
        set { sDescription = value; }
    }

    public String STitle
    {
        get { return sTitle; }
        set { sTitle = value; }
    }

    #endregion

}

#endregion